"""
1.CSS 选择器：BeautifulSoup4的介绍和安装
    介绍:BeautifulSoup4是一个解析器，主要的功能也是如何解析和提取 HTML/XML 数据.
    安装:pip install beautifulsoup4
"""
# 1.1bs4的基本使用示例
# 首先必须要导入 bs4 库
from bs4 import BeautifulSoup


html = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title" name="dromouse"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1"><!-- Elsie --></a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story">...</p>
"""

# 创建BeautifulSoup对象
# soup = BeautifulSoup(html)
# 会存在一段警告,可以通过soup = BeautifulSoup(html,“lxml”)方式指定lxml解析器
# 安装lxml解析器:pip install lxml
soup = BeautifulSoup(html, "lxml")

# 打开本地 HTML 文件的方式来创建BeautifulSoup对象
# soup = BeautifulSoup(open('index.html'))

# 格式化输出 soup 对象的内容
print(type(soup))
print(soup.prettify())
